<template>
	<view class="container">
		<view class="listText">
			<text style="margin-right: 20rpx;" @click="listTextlist">{{app.language.listText6}}</text>
			<text @click="listText">{{app.language.listText4}}</text>
		</view>
		<!-- 基本信息 -->
		<view v-if="currentStep === 0">
			<h2 class="title">{{ app.language.tbrInfo }}</h2>
			<view class="infoBox">
				<!-- 姓名 -->
				<view class="formItem1">
					<text>{{ app.language.name }}:</text>
					<view class="formB">
						{{form.infoname}}
					</view>
				</view>
				<!-- 公民身份证号 -->
				<view class="formItem1">
					<text>{{ app.language.card }}:</text>
					<view class="formB">
						{{form.card}}
					</view>
				</view>
				<!-- 联系电话 -->
				<view class="formItem1">
					<text>{{ app.language.phone }}:</text>
					<view class="formB">
						{{form.phone}}
					</view>
				</view>
			</view>
		</view>
		<view v-if="currentStep === 1">
			<!-- 出租人情况 -->
			<view class="infoBox">
				<h2 class="title">{{app.language.fwcw_cwrInfo}}</h2>
				<!-- 姓名 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.name }}:</text>
					<view class="formB">
						<input type="text" v-model="form.rentName" :placeholder="app.language.Iname" />
					</view>
				</view>
				<!-- 性别 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.gender }}:</text>
					<view class="formB">
						<!-- <input type="text" v-model="form.rentAgent" :placeholder="app.language.Igender"/> -->
						<picker mode="selector" name="gender" :range="genderList" @change="onChangeCzGender">
							<view class="picker">
								{{selectedCzGenderValue}}
							</view>
						</picker>
					</view>
				</view>
				<!-- 民族 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.nation }}:</text>
					<view class="formB">
						<picker mode="selector" name="pcs" :range="list" @change="onChange">
							<view class="picker">
								{{selectedChuzMzValue}}
							</view>
						</picker>
					</view>
				</view>
				<!-- 身份证号码 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.card }}:</text>
					<view class="formB">
						<input type="text" v-model="form.rentIdcard" :placeholder="app.language.Icard" />
					</view>
				</view>
				<!-- 职业 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.fw_career }}:</text>
					<view class="formB">
						<input type="text" v-model="form.rentCareer" :placeholder="app.language.fw_Icareer" />
					</view>
				</view>
				<!-- 户籍所在地 -->
				<view class="formItem1">
					<!-- <text><text class="bt">*</text>{{ app.language.ldy_minorDomicile }}:</text>
					<view class="formB">
						<picker mode="selector" name="hjsx" :range="hjList" @change="onChangehj">
							<view class="picker">
								{{selectedHjValue}}
							</view>
						</picker>
					</view> -->
					<text><text class="bt">*</text>{{ app.language.ldy_minorDomicile }}:</text>
					<!-- 三级联动组件 -->
					<area-picker v-if="areaData.provinces.length > 0" :default-area="defaultArea" :area-data="areaData"
						@change="handleTwoAreaChange" />
				</view>
				<!-- 联系电话 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.phone }}:</text>
					<view class="formB">
						<input type="phone" v-model="form.rentContactNumber" :placeholder="app.language.Iphone" />
					</view>
				</view>
			</view>
			<!-- 房屋情况 -->
			<view class="infoBox">
				<h2 class="title">{{app.language.fw_Info}}</h2>
				<!-- 房屋所在地详址 -->
				<view class="formItem1">
					<!-- <text><text class="bt">*</text>{{ app.language.fw_address }}:</text>
					<view class="formB">
						<picker mode="selector" name="hjsx" :range="hjList" @change="onChangefwszd">
							<view class="picker">
								{{selectedFwszdValue}}
							</view>
						</picker>
					</view> -->
					<text><text class="bt">*</text>{{ app.language.fw_address }}:</text>
					<!-- 三级联动组件 -->
					<area-picker v-if="areaData.provinces.length > 0" :default-area="defaultArea1" :area-data="areaData"
						@change="handleThreeAreaChange" />
				</view>
				<!-- 房屋所在地详细地址 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.jhl }}:</text>
					<view class="formB">
						<input type="text" v-model="form.community" :placeholder="app.language.ijhl" />
					</view>
				</view>
				<!-- 管辖派出所 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.gxsldw }}:</text>
					<view class="formB">
						<picker mode="selector" name="pcs" :range="pcsLists" @change="onpcsChange">
							<view class="picker">
								{{selectedValue}}
							</view>
						</picker>
					</view>
				</view>
				<!-- 承租时间 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.fw_lesseeTime }}:</text>
					<view class="formB">
						<picker mode="date" :value="time" :start="startDate" :end="endDate" @change="bindDateChange">
							<view class="uni-input">{{time}}</view>
						</picker>
					</view>
				</view>
				<!-- 用途 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.fw_purpose }}:</text>
					<view class="formB">
						<input type="text" v-model="form.purpose" :placeholder="app.language.fw_Ipurpose" />
					</view>
				</view>
				<!-- 是否出租 -->
				<view class="formItem1">
					<text>{{ app.language.hetong }}:</text>
					<view class="formB">
						<radio-group @change="handleChangeht" class="radioGroup" v-model="form.iscz">
						  <label v-for="item in htongoptions" :key="item.value">
						    <radio :value="item.value" :checked="form.iscz === item.value"/>
						    {{item.label}}
						  </label>
						</radio-group>
					</view>
				</view>
				<!-- 房屋概貌照 -->
				<view class="formItem">
					<text><text class="bt">*</text>{{ app.language.fw_images }}:</text>
					<view class="hjbImg hjbImg1">
						<button type="default" @click="chooseImg(1)">{{ app.language.scimg }}</button>
					</view>
					<view class="scimageBox" v-if="jmhkbImg.length>0">
						<view class="del3" @click="delImg(jmhkbImg,1)">
							<image class="delImg" src="/static/dels.png"></image>
						</view>
						<image class="scimage" :src="apiUrl+item" v-for="(item,index) in jmhkbImg" :key='index'
							@click="previewImg(item)"></image>
					</view>
					<!-- <image class="scimage" :src="item" v-for="(item,index) in jmhkbImg" :key='index' @click="previewImg(item)"></image> -->
				</view>
				<!-- 租赁合同照 -->
				<view class="formItem">
					<text><text class="bt">*</text>{{ app.language.fw_contractImgs }}:</text>
					<view class="hjbImg hjbImg1">
						<button type="default" @click="chooseImg(2)">{{ app.language.scimg }}</button>
					</view>
					<view class="scimageBox" v-if="zlhtImg.length>0">
						<view class="del3" @click="dlImg(zlhtImg,2)">
							<image class="delImg" src="/static/dels.png"></image>
						</view>
						<image class="scimage" :src="apiUrl+item" v-for="(item,index) in zlhtImg" :key='index'
							@click="previewImg(item)"></image>
					</view>
					<!-- <image class="scimage" :src="item" v-for="(item,index) in zlhtImg" :key='index' @click="previewImg(item)"></image> -->
				</view>
				<!-- 监控数量 -->
				<view class="formItem">
					<text><text class="bt">*</text>{{ app.language.fw_monitorNum }}:</text>
					<view class="hjbImg hjbImg1">
						<button type="default" @click="chooseImg(3)">{{ app.language.scimg }}</button>
					</view>
					<view class="scimageBox" v-if="jkImg.length>0">
						<view class="del3" @click="delImg(jkImg,3)">
							<image class="delImg" src="/static/dels.png"></image>
						</view>
						<image class="scimage" :src="apiUrl+item" v-for="(item,index) in jkImg" :key='index'
							@click="previewImg(item)"></image>
					</view>
					<!-- <image class="scimage" :src="item" v-for="(item,index) in jkImg" :key='index' @click="previewImg(item)"></image> -->
				</view>
			</view>
		</view>
		<view v-if="currentStep === 2">
			<h2 class="title">{{app.language.fwcw_czrInfo}}</h2>
			<view class="infoBox">
				<!-- 姓名 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.name }}:</text>
					<view class="formB">
						<input type="text" v-model="form.name" :placeholder="app.language.Iname" />
					</view>
				</view>
				<!-- 性别 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.gender }}:</text>
					<view class="formB">
						<picker mode="selector" name="gender" :range="genderList" @change="onChangeGender">
							<view class="picker">
								{{selectedGenderValue}}
							</view>
						</picker>
					</view>
				</view>
				<!-- 民族 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.nation }}:</text>
					<view class="formB">
						<picker mode="selector" name="pcs" :range="list" @change="onCzChange">
							<view class="picker">
								{{selectedCzValue}}
							</view>
						</picker>
					</view>
				</view>
				<!-- 身份证号码 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.card }}:</text>
					<view class="formB">
						<input type="text" v-model="form.idcard" :placeholder="app.language.Icard" />
					</view>
				</view>
				<!-- 职业 -->
				<view class="formItem1">
					<text><text class="bt">*</text>{{ app.language.fw_career }}:</text>
					<view class="formB">
						<input type="text" v-model="form.career" :placeholder="app.language.fw_Icareer" />
					</view>
				</view>
				<!-- 户籍所在地 -->
				<view class="formItem1">
					<!-- <text><text class="bt">*</text>{{ app.language.ldy_minorDomicile }}:</text>
					<view class="formB">
						<input type="text" v-model="form.nativePlace" :placeholder="app.language.ldy_IminorDomicile" />
					</view> -->
					<text><text class="bt">*</text>{{ app.language.ldy_minorDomicile }}:</text>
					<!-- 三级联动组件 -->
					<area-picker v-if="areaData.provinces.length > 0" :default-area="defaultArea2" :area-data="areaData"
						@change="handlefAreaChange" />
				</view>
			</view>
		</view>
		<view v-if="currentStep === 3">
			<h2 class="title">{{ app.language.fw_stayInfo }}</h2>
			<view class="infoBox">
				<view class="form" v-for="(item, index) in rentPeople" :key="index">
					<image src="../../static/del.png" mode="" class="del" v-if="index>0" @click="handleDel(index)">
					</image>
					<!-- 关系 -->
					<view class="formItem1">
						<text>{{ app.language.fw_rela }}:</text>
						<view class="formB">
							<input type="text" v-model="rentPeople[index].relationship"
								:placeholder="app.language.fw_Irela" />
						</view>
					</view>
					<!-- 姓名 -->
					<view class="formItem1">
						<text>{{ app.language.name }}:</text>
						<view class="formB">
							<input type="text" v-model="rentPeople[index].name" :placeholder="app.language.Iname" />
						</view>
					</view>
					<!-- 性别 -->
					<view class="formItem1">
						<text>{{ app.language.gender }}:</text>
						<view class="formB">
							<picker mode="selector" name="gender" :range="genderList"
								@change="onChangeGxGender(index, $event)">
								<view class="picker">
									{{rentPeople[index].xb}}
								</view>
							</picker>
						</view>
					</view>
					<!-- 出生年月 -->
					<view class="formItem1">
						<text>{{ app.language.fw_csDate }}:</text>
						<view class="formB">
							<picker mode="date" :value="rentPeople[index].birthdate" :start="startDate" :end="endDate"
								@change="bindCsChange(index, $event)">
								<view class="uni-input">{{rentPeople[index].birthdate}}</view>
							</picker>
						</view>
					</view>
					<!-- 身份证号码 -->
					<view class="formItem1">
						<text>{{ app.language.ldy_card }}:</text>
						<view class="formB">
							<input type="text" v-model="rentPeople[index].idcard"
								:placeholder="app.language.ldy_Icard" />
						</view>
					</view>
				</view>
			</view>
			<!-- 新增随住人员 -->
			<view class="txry" @click="handleAdd">
				<view class="jia">
					<image src="../../static/jiahao.png" mode="" class="icon"></image>
					<text>{{ app.language.addText }}</text>
				</view>
			</view>
		</view>

		<view>
			<button v-if="currentStep > 0" @click="previousStep"
				class="previousStep">{{ app.language.previousStep }}</button>
			<button v-if="currentStep < steps.length - 1" @click="nextStep"
				class="nextStep">{{ app.language.nextStep }}</button>
			<button v-if="currentStep === steps.length - 1&&istj&&!isxg" @click="submitForm(0)"
				class="submitForm">{{ app.language.tijiao }}</button>
			<button v-if="currentStep === steps.length - 1&&!istj&&isxg" @click="submitForm(1)"
				class="submitForm">{{ app.language.djxg }}</button>
		</view>
	</view>
</template>

<script>
	import graceChecker from "../../components/graceChecker.js"
	import {
		AddHous,
		getHous,
		xgHous
	} from '@/api/form.js'
	import {
		getNationality,
		getJgSq,
		geAgent,
		getPcsList
	} from '@/api/api.js'
	const global = getApp().globalData;
	import config from '@/config.js'
	import {
		fetchAndProcessAreaData
	} from '@/api/processCountryData.js';
	import AreaPicker from '@/components/areapicker.vue';
	export default {
		components: {
			AreaPicker
		},
		data() {
			return {
				apiUrl: config.baseUrl,
				rlsb: true,
				app: {
					global: global,
					name: global.appName,
					language: global.language
				},
				// 填表人信息
				form: {
					infoname: "",
					card: "",
					phone: "",
					chooseImags: []
				},
				currentStep: 0,
				steps: [{
						id: 0,
						title: '填表人基本信息'
					},
					{
						id: 1,
						title: '出租人情况'
					},
					{
						id: 2,
						title: '承租人情况'
					},
					{
						id: 3,
						title: '随住人员'
					},
				],
				// 民族列表
				list: [],
				// 性别
				xingbieList: [],
				// 出租人民族
				selectedChuzMzValue: '',
				chuZId: "",
				ChuzMzList: [],
				// 承租人民族
				selectedCzValue: '',
				czId: "",
				CzMzList: [],
				rentPeople: [{
					xb: "",
					birthdate: "",
					idcard: "",
					name: "",
					relationship: "",
				}],
				// 性别
				genderList: [],
				// 承租性别
				selectedGenderValue: "",
				// 出租性别
				selectedCzGenderValue: "",
				// 房屋概貌照片
				jmhkbImg: [],
				// 合同照片
				zlhtImg: [],
				// 监控数量
				jkImg: [],
				// 承租时间
				time: '',
				token: "",
				// 户籍所在地列表
				hjList: [],
				selectedHjValue: "",
				// 房屋所在地详细地址
				selectedFwszdValue: "",
				selectedttwszdValue: "",


				// 派出所
				pcsList: [],
				pcsLists: [],
				selectedValue: "",
				userInfo: {},
				areaData: {
					provinces: [],
					cities: {},
					areas: {}
				},
				defaultArea: "",
				defaultArea1:"",
				defaultArea2:"",
				uuid:"",
				isxg : false,
				istj : true,
				htongoptions: [
				  { value: "0", label: "" },
				  { value: "1", label: "" }
				],

			};
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		async onLoad(options) {
			this.uuid = options.id,
			uni.showLoading({
				title: this.app.language.jzz,
			});
			this.selectedChuzMzValue = this.app.language.qxz
			this.selectedCzValue = this.app.language.qxz
			this.rentPeople[0].xb = this.app.language.qxz
			this.rentPeople[0].birthdate = this.app.language.qxz
			this.selectedGenderValue = this.app.language.qxz
			this.selectedCzGenderValue = this.app.language.qxz
			this.time = this.app.language.qxz
			this.selectedHjValue = this.app.language.qxz
			this.selectedFwszdValue = this.app.language.qxz
			this.selectedValue = this.app.language.qxz
			this.selectedttwszdValue = this.app.language.qxz
			this.htongoptions[0].label = this.app.language.yes
			this.htongoptions[1].label = this.app.language.no
			this.areaData = await fetchAndProcessAreaData();
			this.getToken()
			this.getMzList()
			this.getagent();
			this.getPcs();
		},
		methods: {
			// 获取缓存
			getToken() {
				let that = this
				uni.getStorage({
					key: 'loginData',
					success: function(res) {
						that.form.reportType = res.data.userInfo.peopleType
						that.token = res.data.userInfo.appToken
						that.userInfo = res.data.userInfo
						that.form.phone = res.data.phone
						that.form.phone = res.data.userInfo.phonenumber
						that.form.infoname = res.data.userInfo.userName
						that.form.card = res.data.userInfo.idcard
						if(that.token&&that.uuid){
							that.getinfo()
						}
						uni.hideLoading();
						
					}
				});
			},
			getinfo(){
				uni.showLoading({
					title: this.app.language.jzz
				});
				let data = {
					uuid:this.uuid,
					appToken:this.token
				}
				getHous(data).then((res) => {
					if (res.code == 200) {
						this.form = res.data[0]
						this.form.phone = this.userInfo.phonenumber
						this.form.infoname = this.userInfo.userName
						this.form.card = this.userInfo.idcard
						this.selectedCzValue = res.data[0].nationality
						this.time = res.data[0].approvalTime
						if(this.form.rentPeople){
							this.rentPeople = this.form.rentPeople
							// 循环性别遍历数据
							for (let a = 0; a < this.rentPeople.length; a++) {
								for (let i = 0; i < this.xingbieList.length; i++) {
									if (this.rentPeople[a].agent == this.xingbieList[i].dictValue) {
										this.rentPeople[a].xb = this.xingbieList[i].dictLabel
									}
								}
							}
						}
						// 房屋概貌图
						this.jmhkbImg = res.data[0].housePhoto.split(',')
						// 租赁合同
						this.zlhtImg = res.data[0].leaseContractPhoto.split(',')
						// 监控数量
						this.jkImg = res.data[0].monitoringQuantity.split(',')
						// 循环派出所遍历数据
						for (let i = 0; i < this.pcsList.length; i++) {
							if (this.form.policeStation == this.pcsList[i].deptId) {
								this.selectedValue = this.pcsList[i].deptName
							}
						}
						// 循环出租人民族遍历数据
						for (let i = 0; i < this.ChuzMzList.length; i++) {
							if (this.form.rentNationality == this.ChuzMzList[i].dictValue) {
								this.selectedChuzMzValue = this.ChuzMzList[i].dictLabel
							}
						}
						// 循环性别遍历数据
						for (let i = 0; i < this.xingbieList.length; i++) {
							if (this.form.rentAgent == this.xingbieList[i].dictValue) {
								this.selectedCzGenderValue = this.xingbieList[i].dictLabel
							}
						}
						// 循环承租人性别遍历数据
						for (let i = 0; i < this.xingbieList.length; i++) {
							if (this.form.agent == this.xingbieList[i].dictValue) {
								this.selectedGenderValue = this.xingbieList[i].dictLabel
							}
						}
						// 出租人房屋详细地址回显
						if(this.form.rentNativePlace){
							let address = this.form.rentNativePlace.split(' ')
							let provinceName = address[0]
							let cityName = address[1]
							let areaName = address[2]
							// 1. 查找省份
							let province = this.areaData.provinces.find(
								p => p.name === provinceName
							);
							if (!province) return;
							
							// 2. 查找城市
							let cities = this.areaData.cities[province.code] || [];
							let city = cities.find(
								c => c.name === cityName
							);
							if (!city) return;
							
							// 3. 查找区县
							let areas = this.areaData.areas[city.code] || [];
							let area = areas.find(
								a => a.name === areaName
							);
							if (!area) return;
							
							// 设置默认区域
							this.defaultArea = {
								province,
								city,
								area
							};
						}
						
						// 房屋地址回显
						if(this.form.houseLocation){
							let address1 = this.form.houseLocation.split(' ')
							let provinceName1 = address1[0]
							let cityName1 = address1[1]
							let areaName1 = address1[2]
							// 1. 查找省份
							let province1 = this.areaData.provinces.find(
								p => p.name === provinceName1
							);
							if (!province1) return;
							
							// 2. 查找城市
							let cities1 = this.areaData.cities[province1.code] || [];
							let city1 = cities1.find(
								c => c.name === cityName1
							);
							if (!city1) return;
							
							// 3. 查找区县
							let areas1 = this.areaData.areas[city1.code] || [];
							let area1 = areas1.find(
								a => a.name === areaName1
							);
							if (!area1) return;
							
							// 设置默认区域
							this.defaultArea1 = {
								province1,
								city1,
								area1
							};
						}
						
						// 承租人房屋地址回显
						if(this.form.nativePlace){
							let address2 = this.form.nativePlace.split(' ')
							let provinceName2 = address2[0]
							let cityName2 = address2[1]
							let areaName2 = address2[2]
							// 1. 查找省份
							let province2 = this.areaData.provinces.find(
								p => p.name === provinceName2
							);
							if (!province2) return;
							
							// 2. 查找城市
							let cities2 = this.areaData.cities[province2.code] || [];
							let city2 = cities2.find(
								c => c.name === cityName2
							);
							if (!city2) return;
							
							// 3. 查找区县
							let areas2 = this.areaData.areas[city2.code] || [];
							let area2 = areas2.find(
								a => a.name === areaName2
							);
							if (!area2) return;
							
							// 设置默认区域
							this.defaultArea2 = {
								province2,
								city2,
								area2
							}
						}
						this.isxg = true
						this.istj = false
						uni.hideLoading();
					}
				})
			},
			
			// 是否出租
			handleChangeht(e) {
				this.form.iscz = e.detail.value;
			},

			// 下一步
			nextStep() {
				console.log('currentStep', this.currentStep)
				if (this.currentStep == 0) {
					if (this.currentStep < this.steps.length - 1) {
						this.currentStep++;
					}
					return
				}
				if (this.currentStep == 1) {
					// 出租人姓名
					if (!this.form.rentName) {
						uni.showToast({
							title: this.app.language.iczrName,
							icon: 'none',
						});
						return
					}
					// 出租人性别
					if (!this.selectedCzGenderValue || this.selectedCzGenderValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.Igender,
							icon: 'none',
						});
						return
					}
					// 出租人民族
					if (!this.selectedChuzMzValue || this.selectedChuzMzValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.ination,
							icon: 'none',
						});
						return
					}
					// 出租人身份证号
					if (!this.form.rentIdcard) {
						uni.showToast({
							title: this.app.language.ldy_Icard,
							icon: 'none',
						});
						return
					}
					// 出租人职业
					if (!this.form.rentCareer) {
						uni.showToast({
							title: this.app.language.fw_Icareer,
							icon: 'none',
						});
						return
					}
					// 出租人户籍所在地
					if (!this.selectedHjValue || this.selectedHjValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.ldy_IminorDomicile,
							icon: 'none',
						});
						return
					}
					// 出租人联系电话
					if (!this.form.rentContactNumber) {
						uni.showToast({
							title: this.app.language.Iphone,
							icon: 'none',
						});
						return
					}
					// 房屋所在地详细地址
					if (!this.selectedFwszdValue || this.selectedFwszdValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.fw_Iaddress,
							icon: 'none',
						});
						return
					}
					// 详细地址
					if (!this.form.community) {
						uni.showToast({
							title: this.app.language.jhls,
							icon: 'none',
						});
						return
					}
					// 管辖派出所
					if (!this.selectedValue || this.selectedValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.hjpcsTx,
							icon: 'none',
						});
						return
					}
					// 承租时间
					if (!this.time || this.time === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.fw_ilesseeTime,
							icon: 'none',
						});
						return
					}
					// 用途
					if (!this.form.purpose) {
						uni.showToast({
							title: this.app.language.fw_Ipurpose,
							icon: 'none',
						});
						return
					}
					// 房屋概貌照
					if (this.jmhkbImg.length == 0) {
						uni.showToast({
							title: this.app.language.fw_iimages,
							icon: 'none',
						});
						return
					}
					// 租赁合同照片
					if (this.zlhtImg.length == 0) {
						uni.showToast({
							title: this.app.language.fw_icontractImgs,
							icon: 'none',
						});
						return
					}
					// 监控数量
					if (this.jkImg.length == 0) {
						uni.showToast({
							title: this.app.language.fw_imonitorNum,
							icon: 'none',
						});
						return
					}

					console.log('通过1')
					if (this.currentStep < this.steps.length - 1) {
						this.currentStep++;
					}
					return
				}
				if (this.currentStep == 2) {
					// 承租人姓名
					if (!this.form.name) {
						uni.showToast({
							title: this.app.language.Iname,
							icon: 'none',
						});
						return
					}
					// 承租人性别
					if (!this.selectedGenderValue || this.selectedGenderValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.Igender,
							icon: 'none',
						});
						return
					}
					// 承租人民族
					if (!this.selectedCzValue || this.selectedCzValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.ination,
							icon: 'none',
						});
						return
					}
					// 承租人身份证号
					if (!this.form.idcard) {
						uni.showToast({
							title: this.app.language.ldy_Icard,
							icon: 'none',
						});
						return
					}
					// 承租人职业
					if (!this.form.career) {
						uni.showToast({
							title: this.app.language.fw_Icareer,
							icon: 'none',
						});
						return
					}
					// 承租人户籍所在地
					if (!this.selectedttwszdValue || this.selectedttwszdValue === this.app.language.qxz) {
						uni.showToast({
							title: this.app.language.ldy_IminorDomicile,
							icon: 'none',
						});
						return
					}

					console.log('通过2')
					if (this.currentStep < this.steps.length - 1) {
						this.currentStep++;
					}
					return
				}
			},
			// 上一步
			previousStep() {
				if (this.currentStep > 0) {
					this.currentStep--;
				}
			},

			// 获取性别
			getagent() {
				geAgent().then((res) => {
					this.xingbieList = res.rows
					for (let i = 0; i < res.rows.length; i++) {
						this.genderList.push(res.rows[i].dictLabel);
					}
				})
			},

			// 获取名族列表
			getMzList() {
				getNationality().then((res) => {
					this.ChuzMzList = res.rows
					for (let i = 0; i < res.rows.length; i++) {
						this.list.push(res.rows[i].dictLabel);
					}
				})
			},

			/// 获取派出所列表
			getPcs() {
				let data = {
					"": ""
				}
				getPcsList(data).then((res) => {
					this.pcsList = res.data
					console.log('this.pcsList1111', this.pcsList)
					console.log('res.data', res.data)
					if (res.code == 200) {
						for (let i = 0; i < res.data.length; i++) {
							this.pcsLists.push(res.data[i].deptName);
						}
					}
				})
			},

			//  form表单+1
			handleAdd() {
				let prem = {
					xb: this.app.language.qxz,
					birthdate: this.app.language.qxz,
					idcard: "",
					name: "",
					relationship: "",
				}
				this.rentPeople.push(prem); // 添加一个新的空表单项
			},

			// // 房屋所在地详细地址

			async loadAreaData() {
				uni.showLoading({
					title: this.app.language.jzz
				});

				try {
					const data = await fetchAndProcessAreaData();
					if (data) {
						this.areaData = data;
					}
					// else {
					// 	uni.showToast({
					// 		title: '加载地区数据失败',
					// 		icon: 'none'
					// 	});
					// }
				} catch (error) {
					console.error('加载地区数据出错:', error);
					// uni.showToast({
					// 	title: '加载地区数据出错',
					// 	icon: 'none'
					// });
				} finally {
					uni.hideLoading();
				}
			},
			// 三级联动
			handleTwoAreaChange(selected) {
				// this.firstSelectedArea = selected;
				console.log('第一个选择器选择:', selected);
				this.selectedFwszdValue = selected.fullText
				this.form.rentNativePlace = selected.fullText
			},

			handleThreeAreaChange(selected) {
				// this.firstSelectedArea = selected;
				console.log('第二个选择器选择:', selected);
				this.selectedHjValue = selected.fullText
				this.form.houseLocation = selected.fullText
			},

			handlefAreaChange(selected) {
				// this.firstSelectedArea = selected;
				console.log('第三个选择器选择:', selected);
				this.selectedttwszdValue = selected.fullText
				this.form.nativePlace = selected.fullText
			},


			// 出租人选择性别
			onChangeCzGender(e) {
				this.selectedCzGenderValue = this.xingbieList[e.detail.value].dictLabel;
				this.form.rentAgent = this.xingbieList[e.detail.value].dictValue;
			},

			// 选择出租人的民族
			onChange(e) {
				this.selectedChuzMzValue = this.ChuzMzList[e.detail.value].dictLabel;
				this.form.rentNationality = this.ChuzMzList[e.detail.value].dictValue;
				this.chuZId = this.ChuzMzList[e.detail.value].dictValue;
			},

			// 出租人时间选择
			bindDateChange(e) {
				this.time = e.detail.value
				this.form.approvalTime = e.detail.value
			},

			// 承租选择性别
			onChangeGender(e) {
				this.selectedGenderValue = this.genderList[e.detail.value];
				this.form.agent = this.xingbieList[e.detail.value].dictValue;
			},

			// 选择承租人的民族
			onCzChange(e) {
				this.selectedCzValue = this.list[e.detail.value];
				this.form.nationality = this.list[e.detail.value];
				this.czId = this.ChuzMzList[e.detail.value].dictValue;
			},

			// 选择管辖派出所
			onpcsChange(e) {
				this.selectedValue = this.pcsLists[e.detail.value];
				this.form.policeStation = this.pcsList[e.detail.value].deptId;
				console.log('this.form.policeStation', this.form.policeStation)
			},

			// 随住人员性别
			onChangeGxGender(index, e) {
				this.rentPeople[index].xb = this.genderList[e.detail.value];
				this.rentPeople[index].agent = this.xingbieList[e.detail.value].dictValue;
			},

			// 随住人员出生年月日
			bindCsChange(index, e) {
				this.rentPeople[index].birthdate = e.detail.value;
				console.log('333333333', this.rentPeople[index].birthdate)
				// this.form.birthdate = e.detail.value
			},



			// 上传图片
			chooseImg(item) {
				console.log('3333333', item)
				uni.chooseImage({
					count: 8,
					success: (res) => {
						this.srcImg = res.tempFilePaths


						let tempFilePaths = res.tempFilePaths;
						// this.tempFilePathList = res.tempFilePaths;
						let base64List = this.form.chooseImags;
						// 图片路径转换成base64格式
						tempFilePaths.forEach((item, index) => {
							uni.getFileSystemManager().readFile({
								filePath: item, // 图片文件路径
								encoding: 'base64', // 编码格式为base64
								success: res => { // 成功回调
									let base64 = 'data:image/jpeg;base64,' + res
										.data; // 拼接data URI
									base64List.push(base64);
									if (base64List.length === tempFilePaths.length) {
										this.form.chooseImags = base64List;
									}
								},
								fail: err => {
									console.error('读取文件失败', err);
								}
							});
						});

						// 上传图片并返回路径
						let imgList = [];
						// 上传前显示加载中
						uni.showLoading({
							title: this.app.language.jzz,
						});
						tempFilePaths.forEach((tempFilePaths) => {
							const uploadTask = uni.uploadFile({
								url: 'https://mqzhian.cn:8088/common/upload', // 你的ThinkPHP服务器地址
								filePath: tempFilePaths,
								name: 'file', // 这里根据服务器接收的字段来定义
								success: (uploadFileRes) => {
									const data = JSON.parse(uploadFileRes.data);
									console.log('上传成功', data);
									// 上传成功后隐藏加载中
									uni.hideLoading();
									imgList.push(data.fileName);
									if (item == 1) {
										this.jmhkbImg = imgList
										this.form.housePhoto = imgList.join(',')
									} else if (item == 2) {
										this.zlhtImg = imgList
										this.form.leaseContractPhoto = imgList.join(',')
									} else if (item == 3) {
										this.jkImg = imgList
										this.form.monitoringQuantity = imgList.join(',')
									}
								},
								fail: (error) => {
									console.error('上传失败', error);
									uni.showToast({
										title: this.app.language.scerror,
										icon: 'none',
									});
								}
							});
						});
					}
				})
			},

			// 预览图片
			previewImg(current) {
				uni.previewImage({
					current,
					urls: this.srcImg,
					// 图片指示器样式: 小圆点
					indicator: 'default',
					// 循环预览
					loop: true
				})
			},

			// 删除新增人员  -1
			handleDel(index) {
				let that = this
				// uni.showModal({
				// 	// title: '提示',
				// 	content: '确定要删除吗?',
				// 	success: function(res) {
				// 		if (res.confirm) {

				// 			// 用户点击了确定按钮的相关逻辑可以放在这里
				// 		} else if (res.cancel) {
				// 			console.log('用户点击取消');
				// 			// 用户点击了取消按钮的相关逻辑可以放在这里
				// 		}
				// 	}
				// });
				that.rentPeople.splice(index, 1); // 移除指定索引的表单项
			},

			// 时间-日期
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},

			// 删除图片
			delImg(list, id) {
				console.log('id', id)
				console.log('list', list)
				uni.showModal({
					title: this.app.language.titDel, // 弹框标题
					content: this.app.language.delBtn, // 弹框内容
					cancelText: this.app.language.popCancelText, // 取消按钮文本
					confirmText: this.app.language.okBtn, // 确认按钮文本
					success: (res) => {
						if (res.confirm) {
							// 用户点击了“确定”按钮
							if (id == 1) {
								this.jmhkbImg = []
							} else if (id == 2) {
								this.zlhtImg = []
							} else if (id == 3) {
								this.jkImg = []
							}
						} else if (res.cancel) {
							// 用户点击了“取消”按钮，或者关闭了弹框
							console.log('用户取消删除');
						}
					}
				});
			},
			
			// 跳转信息列表
			listTextlist(){
				console.log('跳转信息列表')
				if (this.token) {
					uni.reLaunch({
						url: '/pages/rentHouse/xxlist'
					});
				}else {
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},

			listText() {
				if (this.token) {
					if (this.userInfo.peopleType == "people") {
						if (!this.userInfo.userName && !this.userInfo.idcard &&
							!this.userInfo.idcardFront && !this.userInfo.idcardBack) {
							uni.showToast({
								title: this.app.language.improve,
								icon: 'none',
							});
							return
						} else {
							uni.reLaunch({
								url: '/pages/rentHouse/listText'
							});
						}
					} else if (this.userInfo.peopleType == "police") {
						if (!this.userInfo.agent && !this.userInfo.birthdate && !this.userInfo.birthdate && !this
							.userInfo
							.nationality && !this.userInfo.policeNumber &&
							!this.userInfo.personnelCategory && !this.userInfo.department && !this.userInfo.workTime &&
							!
							this.userInfo.positionRank &&
							!this.userInfo.marriage && !this.userInfo.height && !this.userInfo.weight && !this.userInfo
							.photo) {
							uni.showToast({
								title: this.app.language.improve,
								icon: 'none',
							});
							return
						} else {
							uni.reLaunch({
								url: '/pages/rentHouse/listText'
							});
						}
					}
				} else {
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},

			//提交 
			submitForm(id) {
				if(id==0){
					// 提交数据 AddHous
					if(this.rentPeople.length>0){
						this.form.rentPeople = this.rentPeople
					}
					this.form.appToken = this.token
					uni.showLoading({
						title: this.app.language.jzz,
					});
					AddHous(this.form).then((res) => {
						if (res.code == 200) {
							uni.hideLoading();
							uni.showToast({
								title: this.app.language.qddsh,
								icon: 'success',
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/rentHouse/listText'
								});
							}, 1000);
						}
					})
				}else if(id==1){
					// 提交数据 AddHous
					if(this.rentPeople.length>0){
						this.form.rentPeople = this.rentPeople
					}
					this.form.appToken = this.token
					uni.showLoading({
						title: this.app.language.jzz,
					});
					xgHous(this.form).then((res) => {
						if (res.code == 200) {
							uni.hideLoading();
							uni.showToast({
								title: this.app.language.qddsh,
								icon: 'success',
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/rentHouse/listText'
								});
							}, 1000);
						}
					})
				}
				// if (this.currentStep == 3) {
				// 	for (let i = 0; i < this.form.rentPeople.length; i++) {
				// 		// 随住人员关系
				// 		if (!this.form.rentPeople[i].relationship) {
				// 			uni.showToast({
				// 				title: this.app.language.fw_Irela,
				// 				icon: 'none',
				// 			});
				// 			return
				// 		}
				// 		// 随住人员姓名
				// 		if (!this.form.rentPeople[i].name) {
				// 			uni.showToast({
				// 				title: this.app.language.iczrName,
				// 				icon: 'none',
				// 			});
				// 			return
				// 		}
				// 		// 随住人员性别
				// 		if (!this.form.rentPeople[i].xb || this.form.rentPeople[i].xb === this.app.language.qxz) {
				// 			uni.showToast({
				// 				title: this.app.language.Igender,
				// 				icon: 'none',
				// 			});
				// 			return
				// 		}
				// 		// 随住人员出生年月
				// 		if (!this.form.rentPeople[i].birthdate || this.form.rentPeople[i].birthdate === this.app.language
				// 			.qxz) {
				// 			uni.showToast({
				// 				title: this.app.language.fw_IcsDate,
				// 				icon: 'none',
				// 			});
				// 			return
				// 		}
				// 		// 随住人员身份证号
				// 		if (!this.form.rentPeople[i].idcard) {
				// 			uni.showToast({
				// 				title: this.app.language.ldy_Icard,
				// 				icon: 'none',
				// 			});
				// 			return
				// 		}

				// 	}
					
				// }

			}
		}
	};
</script>
<style>
	.container {
		padding: 10rpx 20rpx;
	}

	.form {
		border: 1px solid #ddd;
		box-shadow: 1px 1px 10rpx #ddd;
		padding: 0 20rpx;
		margin-top: 20rpx;
		position: relative
	}

	.formItem1,
	.formItem {
		margin: 10rpx 0;
		padding: 10rpx;
		/* height: 162rpx; */
		position: relative;
		border-bottom: 1px dashed #ddd
	}

	.formB {
		/* background-color: #f3f3f3; */
		font-size: 24rpx;
		padding: 10rpx;
		margin-top: 10rpx;
		position: absolute;
		right: 10rpx;
		top: -2rpx;
		color: #808080;
		text-align: right;
	}

	.formItem1 text,
	.formItem text {
		font-size: 26rpx;
	}

	.title {
		border-left: 4rpx solid #2f8ef9;
		padding-left: 10rpx;
		margin: 10rpx 0 10rpx 10rpx;
		font-weight: bold;
		font-size: 26rpx;
	}

	.nextStep,
	.previousStep,
	.submitForm {
		background-color: #2f8ef9;
		color: #fff;
		font-size: 26rpx;
		margin-top: 20rpx;
	}

	.bt {
		color: red;
		margin-right: 5rpx;
	}

	.hjbImg button {
		font-size: 22rpx;
		width: 149rpx;
		height: 56rpx;
		background: #2f8ef9;
		color: #fff;
	}

	.hjbImg {
		/* position: absolute;
		bottom: 10rpx; */
		width: 150rpx;
		margin-top: -17rpx;
	}

	.hjbImg1 {
		width: 150rpx;
		margin-top: 20rpx !important;
	}

	.jia {
		border: 1px dashed #2f8ef9;
		text-align: center;
		color: #2f8ef9;
		margin: 20rpx auto 0;
		font-size: 26rpx;
		border-radius: 10rpx;
		padding: 0 0 13rpx;
	}

	.jia image {
		width: 40rpx;
		height: 40rpx;
		position: relative;
		top: 8rpx;
	}

	.del {
		width: 25px;
		height: 25px;
		position: absolute;
		right: -5px;
		top: -8px;
	}

	.radioGroup {
		position: relative;
		top: -13rpx;
	}

	.polSta {
		font-size: 26rpx;
		font-weight: 500;
		/* text-align: right; */
		color: #2f8ef9;
		margin-top: 15rpx;
	}

	.picker,
	.uni-input {
		width: 260rpx;
		color: #808080;
	}

	.scimageBox {
		display: inline-block;
		width: 100%;
		height: 100rpx;
		position: relative;
		/* text-align: center; */
	}

	.scimage {
		width: 121rpx;
		height: 80rpx;
		margin-right: 10rpx;
		margin-top: 5px;
		border-radius: 5rpx;
	}

	.del3 {
		color: red;
		font-size: 26rpx;
		text-align: right;
		width: 50rpx;
		height: 50rpx;
		position: absolute;
		right: 0;
		top: -43rpx;
	}

	.delImg {
		width: 50rpx;
		height: 50rpx;
	}

	.listText {
		font-size: 28rpx;
		color: #2f8ef9;
		margin: 15rpx 0;
		text-align: right;
		font-weight: 500;
		/* border-bottom: 1px solid #ddd; */
		padding-bottom: 10rpx;
	}

	.listText text {
		border: 1px solid #2f8ef9;
		padding: 10rpx 15rpx;
		border-radius: 6rpx;
	}
</style>